package org.exhaust.barbecue.spring;

import org.springframework.beans.factory.FactoryBean;

/**
 * MapperFactoryBean
 */
public class ManagerFactoryBean<T> implements FactoryBean<T> {

    private Class<T> managerInterface;

    public ManagerFactoryBean() {
    }

    /**
     * 被Spring框架反射调用了
     *
     * @param managerInterface
     */
    public ManagerFactoryBean(Class<T> managerInterface) {
        this.managerInterface = managerInterface;
    }

    @Override
    public T getObject() throws Exception {
        return (T) ManagerProxyFactory.newInstance(managerInterface);
    }

    @Override
    public Class<?> getObjectType() {
        return this.managerInterface;
    }

    public void setManagerInterface(Class<T> managerInterface) {
        this.managerInterface = managerInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
